package com.michael.study.jetpack.module.video;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.widget.Toast;

import com.michael.study.jetpack.R;

import java.io.IOException;

import tv.danmaku.ijk.media.player.IMediaPlayer;

public class VideoActivity extends AppCompatActivity implements VideoListener {

    private VideoPlayer mVideoPlayer;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_video);
        mVideoPlayer = findViewById(R.id.video_player);

        mVideoPlayer.setVideoListener(this);
        mVideoPlayer.setPath("http://s3.cn-northwest-1.amazonaws.com.cn/default.auteltest/0ab56c7c-c7d9-4e1f-a4e2-4c786d41bf46");
        try {
            mVideoPlayer.load();
        } catch (IOException e) {
            Toast.makeText(this,"播放失败",Toast.LENGTH_SHORT);
            e.printStackTrace();
        }
    }

    @Override
    public void onBufferingUpdate(IMediaPlayer iMediaPlayer, int i) {

    }

    @Override
    public void onCompletion(IMediaPlayer iMediaPlayer) {

    }

    @Override
    public boolean onError(IMediaPlayer iMediaPlayer, int i, int i1) {
        return false;
    }

    @Override
    public boolean onInfo(IMediaPlayer iMediaPlayer, int i, int i1) {
        return false;
    }

    @Override
    public void onPrepared(IMediaPlayer iMediaPlayer) {
        if (mVideoPlayer != null) {
            mVideoPlayer.start();
        }
    }

    @Override
    public void onSeekComplete(IMediaPlayer iMediaPlayer) {

    }

    @Override
    public void onVideoSizeChanged(IMediaPlayer iMediaPlayer, int i, int i1, int i2, int i3) {

    }
}